﻿<UserControl x:Class="Soat.HappyNet.Silverlight.Modules.BackOffice.Views.OrderDetailsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:controls="clr-namespace:Soat.HappyNet.Silverlight.Library.Controls;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:behavior="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:action="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Actions;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:trigger="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Triggers;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
    <Grid x:Name="LayoutRoot">
        
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="DetailsVisibility">
    			<VisualStateGroup.Transitions>
    				<VisualTransition From="NoDetails" GeneratedDuration="00:00:00.5000000" To="DetailsVisible">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.Opacity)">
    							<EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
    							<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0.2"/>
    							<EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1">
    								<EasingDoubleKeyFrame.EasingFunction>
    									<CubicEase EasingMode="EaseOut"/>
    								</EasingDoubleKeyFrame.EasingFunction>
    							</EasingDoubleKeyFrame>
    						</DoubleAnimationUsingKeyFrames>
    						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
    							<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0.2"/>
    							<EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1">
    								<EasingDoubleKeyFrame.EasingFunction>
    									<CubicEase EasingMode="EaseOut"/>
    								</EasingDoubleKeyFrame.EasingFunction>
    							</EasingDoubleKeyFrame>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualTransition>
    				<VisualTransition From="DetailsVisible" GeneratedDuration="00:00:00.5000000" To="NoDetails">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
    							<EasingDoubleKeyFrame KeyTime="00:00:00.6000000" Value="60">
    								<EasingDoubleKeyFrame.EasingFunction>
    									<CircleEase EasingMode="EaseOut"/>
    								</EasingDoubleKeyFrame.EasingFunction>
    							</EasingDoubleKeyFrame>
    						</DoubleAnimationUsingKeyFrames>
    						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.Opacity)">
    							<EasingDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualTransition>
    			</VisualStateGroup.Transitions>
    			<VisualState x:Name="NoDetails">
    				<Storyboard>
    					<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.Opacity)">
    						<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
    					</DoubleAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="DetailsVisible">
    				<Storyboard>
    					<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="OrderInvoiceBorder" Storyboard.TargetProperty="(UIElement.Opacity)">
    						<EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
    					</DoubleAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>

        <TextBlock Text="Sélectionnez une commande dans la colonne de gauche pour voir ses détails" Foreground="#33000000" TextAlignment="Center"
                   FontSize="40" FontFamily="Trebuchet MS" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" TextWrapping="Wrap">
            <i:Interaction.Behaviors>
                <behavior:NullValueVisibilityBehavior ValueBinding="{Binding CurrentOrder}" Negate="True" />
            </i:Interaction.Behaviors>
        </TextBlock>
        
        <Border x:Name="OrderInvoiceBorder" RenderTransformOrigin="0.5,0.5">
            <i:Interaction.Behaviors>
                <behavior:NullValueVisibilityBehavior ValueBinding="{Binding CurrentOrder}" />
            </i:Interaction.Behaviors>
            
            <Border.Projection>
        		<PlaneProjection CenterOfRotationX="0"/>
        	</Border.Projection>
            
            <Border.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Border.RenderTransform>

            <Grid DataContext="{Binding CurrentOrder}" Margin="0,0,10,10">

                <Grid.Effect>
                    <DropShadowEffect BlurRadius="12" ShadowDepth="4" Opacity="0.5"/>
                </Grid.Effect>

                <Grid.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFD5D8DA" Offset="1"/>
                        <GradientStop Color="White"/>
                    </LinearGradientBrush>
                </Grid.Background>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <StackPanel Margin="10" Orientation="Vertical" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
                    <StackPanel Orientation="Horizontal" Margin="10">
                        <TextBlock Text="Commande n°" VerticalAlignment="Bottom" FontFamily="Georgia" FontSize="24" FontStyle="Italic" Foreground="#80000000"/>
                        <TextBlock Text="{Binding SalesOrderNumber}" VerticalAlignment="Bottom" FontFamily="Trebuchet MS" FontSize="24" Foreground="#FF000000" Margin="5,0,0,0"/>
                        <TextBlock Text="(" VerticalAlignment="Bottom" Foreground="#80000000" Margin="10,0,0,0"/>
                        <TextBlock Text="{Binding SalesOrderID}" VerticalAlignment="Bottom" Foreground="#80000000"/>
                        <TextBlock Text=")" VerticalAlignment="Bottom" Foreground="#80000000"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="10">
                        <TextBlock Text="Client : " FontStyle="Italic" Foreground="#80000000"/>
                        <TextBlock Text="{Binding Customer.Person.FirstName}" Margin="0,0,4,0" FontWeight="Bold"/>
                        <TextBlock Text="{Binding Customer.Person.MiddleName}" Margin="0,0,4,0" FontWeight="Bold"/>
                        <TextBlock Text="{Binding Customer.Person.LastName}" FontWeight="Bold"/>
                    </StackPanel>
                </StackPanel>

                <Grid Margin="20" Background="White" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
                    <Grid.Effect>
                        <DropShadowEffect Opacity="0.2" ShadowDepth="2" BlurRadius="4"/>
                    </Grid.Effect>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel Orientation="Vertical" Grid.Column="0" Margin="10">
                        <TextBlock Text="Adresse de facturation" FontWeight="Bold">
                    <TextBlock.Foreground>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF245586" Offset="1"/>
                            <GradientStop Color="#FF0081FF"/>
                        </LinearGradientBrush>
                    </TextBlock.Foreground>
                        </TextBlock>
                        <TextBlock Text="{Binding Address.AddressLine1}"/>
                        <TextBlock Text="{Binding Address.AddressLine2}"/>
                        <TextBlock Text="{Binding Address.City}"/>
                    </StackPanel>

                    <StackPanel Orientation="Vertical" Grid.Column="1" Margin="10">
                        <TextBlock Text="Adresse de livraison" FontWeight="Bold">
                    <TextBlock.Foreground>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF3C7013" Offset="1"/>
                            <GradientStop Color="#FF7DFF00"/>
                        </LinearGradientBrush>
                    </TextBlock.Foreground>
                        </TextBlock>
                        <TextBlock Text="{Binding Address1.AddressLine1}"/>
                        <TextBlock Text="{Binding Address1.AddressLine2}"/>
                        <TextBlock Text="{Binding Address1.City}"/>
                    </StackPanel>
                </Grid>

                <Grid Margin="10" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Stretch">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.Row="0" Margin="10" Text="Liste des produits" FontWeight="Bold"/>

                        <data:DataGrid Grid.Row="1" Margin="10" ItemsSource="{Binding SalesOrderDetail}" CanUserReorderColumns="True" IsReadOnly="True" AutoGenerateColumns="False" Style="{StaticResource DataGridStyle}">
                            <!--TODO-->
                            <data:DataGrid.Columns>
                                <data:DataGridTextColumn Header="Identifiant Commande" Binding="{Binding SalesOrderDetailID}" />
                                <data:DataGridTextColumn Header="Prix unitaire" Binding="{Binding UnitPrice, Converter={StaticResource CurrencyConverter}}" />
                                <data:DataGridTextColumn Header="Quantité" Binding="{Binding OrderQty}" />
                                <data:DataGridTextColumn Header="Total ligne" Binding="{Binding LineTotal, Converter={StaticResource CurrencyConverter}}" />
                            </data:DataGrid.Columns>

                        </data:DataGrid>
                    </Grid>
                </Grid>

                <Grid Margin="20" Grid.Row="3" Grid.Column="1" VerticalAlignment="Bottom">

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="10"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="Sous-total" FontStyle="Italic"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Text="Taxes" FontStyle="Italic"/>
                    <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Text="Frais de port" FontStyle="Italic"/>
                    <TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Text="Total à payer" FontWeight="Bold"/>
                    <TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" Text="{Binding SubTotal, Converter={StaticResource CurrencyConverter}}" FontStyle="Italic"/>
                    <TextBlock Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Text="{Binding TaxAmt, Converter={StaticResource CurrencyConverter}}" FontStyle="Italic"/>
                    <TextBlock Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" Text="{Binding Freight, Converter={StaticResource CurrencyConverter}}" FontStyle="Italic"/>
                    <TextBlock Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right" Text="{Binding TotalDue, Converter={StaticResource CurrencyConverter}}" FontWeight="Bold"/>
                </Grid>
            </Grid>
        </Border>
        
        <controls:Loading IsLoading="{Binding IsLoading}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        
    </Grid>
</UserControl>
